package com.chainyoung.component_tmperson.ui.mvp.presenter;

import com.chainyoung.common.base.CommonSubscriber;
import com.chainyoung.common.exception.ApiException;
import com.chainyoung.common.mvp.BasePresenter;
import com.chainyoung.common.utils.RxUtils;
import com.chainyoung.component_tmperson.entity.WalletDebit;
import com.chainyoung.component_tmperson.entity.WalletFinancing;
import com.chainyoung.component_tmperson.ui.mvp.contract.WalletDebitContract;
import com.chainyoung.component_tmperson.ui.mvp.contract.WalletFinancingMangeContract;

import java.util.List;
import java.util.TreeMap;

import javax.inject.Inject;

import static com.chainyoung.common.constant.LibConstant.NO_RESULT_ERRORCODE;

public class WalletDebitPresenter extends BasePresenter<WalletDebitContract.Model, WalletDebitContract.View> {

    @Inject
    public WalletDebitPresenter(WalletDebitContract.Model model, WalletDebitContract.View rootView) {
        super(model, rootView);
    }


    public void getWalletDebitList(TreeMap<String, Object> map) {

        addSubscribe(mModel.getWalletDebitList(map)
                .compose(RxUtils.<List<WalletDebit>>rxSchedulerHelper())
                .subscribeWith(new CommonSubscriber<List<WalletDebit>>(mView, false) {
                    @Override
                    public void onNext(List<WalletDebit> data) {
                        mView.onGetAllDebitList(data);
                    }

                    @Override
                    public void onError(Throwable e) {
                        if (e instanceof ApiException) {
                            if (((ApiException) e).getErrorCode().equals(NO_RESULT_ERRORCODE)) {
                                mView.onGetAllDebitList(null);
                                return;
                            }
                        }
                        mView.onGetAllDebitListFailed();
                        super.onError(e);
                    }
                }));
    }


}



